var CalendarPlanForm = function(c, d) {
    this.planId = c;
    var a = this.setup();
    var b = new Ext.Window({
        id: "CalendarPlanFormWin",
        iconCls: "menu-cal-plan-view",
        title: "日程详细信息",
        border: false,
        width: 660,
        height: 500,
        maximizable: true,
        modal: true,
        layout: "fit",
        buttonAlign: "center",
        items: [this.setup()],
        buttons: [{
            text: "保存",
            iconCls: "btn-save",
            handler: function() {
                var f = Ext.getCmp("CalendarPlanForm");
                var h = Ext.getCmp("startTime").getValue();
                var e = Ext.getCmp("endTime").getValue();
                var g = Ext.getCmp("taskType1").checked;
                if ((!g) || (g && h != null && h != "" && e != null && e != "")) {
                    if (f.getForm().isValid()) {
                        f.getForm().submit({
                            method: "post",
                            waitMsg: "正在提交数据...",
                            success: function(j, k) {
                                Ext.ux.Toast.msg("操作信息", "成功保存信息！");
                                var i = Ext.getCmp("CalendarPlanGrid");
                                if (i != null) {
                                    i.getStore().reload();
                                }
                                if (d != null) {
                                    d.call(this);
                                }
                                b.close();
                            },
                            failure: function(i, j) {
                                Ext.MessageBox.show({
                                    title: "操作信息",
                                    msg: "信息保存出错，请联系管理员！",
                                    buttons: Ext.MessageBox.OK,
                                    icon: "ext-mb-error"
                                });
                                b.close();
                            }
                        });
                    }
                } else {
                    Ext.ux.Toast.msg("操作信息", "请填写完整开始结束时间！");
                }
            }
        },
        {
            text: "取消",
            iconCls: "btn-cancel",
            handler: function() {
                b.close();
            }
        }]
    });
    b.show();
};
CalendarPlanForm.prototype.setup = function() {
    var a = new Ext.FormPanel({
        url: __ctxPath + "/task/saveCalendarPlan.do",
        layout: "form",
        id: "CalendarPlanForm",
        bodyStyle: "padding:5px;",
        frame: false,
        border: 0,
        defaults: {
            anchor: "98%,98%"
        },
        formId: "CalendarPlanFormId",
        items: [{
            name: "calendarPlan.planId",
            id: "planId",
            xtype: "hidden",
            value: this.planId == null ? "": this.planId
        },
        {
            xtype: "radiogroup",
            fieldLabel: "紧急程度",
            autoHeight: true,
            columns: 3,
            items: [{
                boxLabel: "一般",
                name: "calendarPlan.urgent",
                inputValue: 0,
                id: "urgent0",
                checked: true
            },
            {
                boxLabel: "重要",
                name: "calendarPlan.urgent",
                inputValue: 1,
                id: "urgent1"
            },
            {
                boxLabel: "紧急",
                name: "calendarPlan.urgent",
                inputValue: 2,
                id: "urgent2"
            }]
        },
        {
            fieldLabel: "内容",
            xtype: "htmleditor",
            height: 200,
            name: "calendarPlan.content",
            id: "content",
            allowBlank: false
        },
        {
            fieldLabel: "员工ID",
            xtype: "hidden",
            name: "userId",
            id: "userId",
            value: curUserInfo.userId
        },
        {
            layout: "column",
            autoHeight: true,
            border: false,
            items: [{
                columnWidth: 0.8,
                layout: "form",
                border: false,
                style: "padding-left:0px;",
                items: [{
                    fieldLabel: "分配给",
                    style: "padding-left:0px;",
                    xtype: "textfield",
                    anchor: "100%,100%",
                    name: "calendarPlan.fullname",
                    id: "fullname",
                    value: curUserInfo.fullname
                }]
            },
            {
                columnWidth: 0.2,
                xtype: "button",
                border: false,
                iconCls: "btn-user-sel",
                text: "选择员工",
                handler: function() {
                    UserSelector.getView(function(c, b) {
                        Ext.getCmp("userId").setValue(c);
                        Ext.getCmp("fullname").setValue(b);
                    }).show();
                }
            }]
        },
        {
            xtype: "radiogroup",
            id: "planTypeGroup",
            fieldLabel: "任务类型",
            autoHeight: true,
            columns: 2,
            items: [{
                boxLabel: "限期任务",
                name: "calendarPlan.taskType",
                inputValue: 1,
                id: "taskType1",
                checked: true,
                listeners: {
                    check: function(c, b) {
                        if (b) {
                            Ext.getCmp("timeDuration").setVisible(true);
                            Ext.getCmp("CalenderDisplayType").setVisible(true);
                        }
                    }
                }
            },
            {
                boxLabel: "非限期任务",
                name: "calendarPlan.taskType",
                id: "taskType2",
                inputValue: 2,
                listeners: {
                    check: function(c, b) {
                        if (b) {
                            Ext.getCmp("timeDuration").setVisible(false);
                            Ext.getCmp("CalenderDisplayType").setVisible(false);
                            Ext.getCmp("startTime").setValue("");
                            Ext.getCmp("endTime").setValue("");
                        }
                    }
                }
            }]
        },
        {
            xtype: "fieldset",
            border: false,
            layout: "form",
            id: "timeDuration",
            autoHeight: true,
            style: "padding-left:0px;",
            items: [{
                fieldLabel: "开始时间",
                style: "padding-left:0px;",
                name: "calendarPlan.startTime",
                xtype: "datetimefield",
                id: "startTime",
                anchor: "98%,98%",
                format: "Y-m-d H:i:s"
            },
            {
                fieldLabel: "结束时间",
                style: "padding-left:0px;",
                name: "calendarPlan.endTime",
                xtype: "datetimefield",
                id: "endTime",
                anchor: "98%,98%",
                format: "Y-m-d H:i:s"
            }]
        },
        {
            xtype: "fieldset",
            id: "CalenderDisplayType",
            layout: "form",
            autoHeight: true,
            border: false,
            style: "padding-left:0px;",
            items: [{
                xtype: "radiogroup",
                fieldLabel: "显示方式",
                autoHeight: true,
                columns: 2,
                items: [{
                    boxLabel: "仅在任务中显示",
                    name: "calendarPlan.showStyle",
                    inputValue: 1,
                    id: "showStyle1",
                    checked: true
                },
                {
                    boxLabel: "在日程与任务中显示",
                    name: "calendarPlan.showStyle",
                    id: "showStyle2",
                    inputValue: 2
                }]
            }]
        }]
    });
    if (this.planId != null && this.planId != "undefined") {
        a.getForm().load({
            deferredRender: false,
            url: __ctxPath + "/task/getCalendarPlan.do?planId=" + this.planId,
            waitMsg: "正在载入数据...",
            success: function(b, c) {
                var d = c.result.data;
                Ext.getCmp("urgent" + d.urgent).setValue(true);
                Ext.getCmp("showStyle" + d.showStyle).setValue(true);
                Ext.getCmp("planTypeGroup").setValue("taskType" + d.taskType, true);
            },
            failure: function(b, c) {}
        });
    }
    return a;
};